﻿using Dotnet.Code;
using Dotnet.Sui;
using Sui.Domain.App;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sui.WinForm
{
    public partial class FrmLogin : Form
    {
        public FrmLogin()
        {
            InitializeComponent();
        }
        private string _cookie = "";
        private void Form1_Load(object sender, EventArgs e)
        {
            _cookie = System.IO.File.ReadAllText("Database\\Sui\\cookie.json").Trim();
            txtCookie.Text=_cookie;
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            _cookie=txtCookie.Text;
            txtCookie.Clear();
            TallyNewRmiRequest req = new TallyNewRmiRequest();
            req.Cookie = _cookie;
            req.BeginDate = DateTime.Now.ToString("yyyy.MM.dd");
            req.EndDate= DateTime.Now.ToString("yyyy.MM.dd");
            SuiClient client = new SuiClient();
            TallyNewRmiResponse resp = client.Execute<TallyNewRmiResponse>(req);
            txtCookie.AppendText($"【{resp.ReqUrl}】===============\r\n{resp.Body}\r\n");
            if (resp.Body.StartsWith("{error")) return;
            else
            {
                System.IO.File.WriteAllText("Database\\Sui\\cookie.json",_cookie);
                this.DialogResult=DialogResult.OK;
                this.Close();
            }
        }
    }
}
